#include<bits/stdc++.h>
using namespace std;

int cnt[333];

signed main() {
	int k;
	string s;
	cin >> k >> s;
	int len = s.size();
	if (len % k) {
		cout << "-1";
		return 0;
	}

	int ans = 0;
	int lenPerGroup = len / k;

	for (int i = 0; i < lenPerGroup; i++) {
		memset(cnt, 0, sizeof cnt);
		for (int j = i; j < len; j += lenPerGroup)
			cnt[s[j]]++;
		ans += k - *max_element(cnt + 'a', cnt + 'z' + 1);
	}
	cout << ans;
	return 0;
}
